// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_decimalv2_27_9") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_float_from_decimalv2_27_9_0_nullable;"
    sql "create table test_cast_to_float_from_decimalv2_27_9_0_nullable(f1 int, f2 decimalv2(27, 9)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimalv2_27_9_0_nullable values (0, "0.000000000"),(1, "0.000000000"),(2, "0.000000001"),(3, "-0.000000001"),(4, "0.000000009"),(5, "-0.000000009"),(6, "0.099999999"),(7, "-0.099999999"),(8, "0.900000000"),(9, "-0.900000000"),(10, "0.900000001"),(11, "-0.900000001"),(12, "0.999999998"),(13, "-0.999999998"),(14, "0.999999999"),(15, "-0.999999999"),(16, "1.000000000"),(17, "-1.000000000"),(18, "1.000000001"),(19, "-1.000000001"),
      (20, "1.000000009"),(21, "-1.000000009"),(22, "1.099999999"),(23, "-1.099999999"),(24, "1.900000000"),(25, "-1.900000000"),(26, "1.900000001"),(27, "-1.900000001"),(28, "1.999999998"),(29, "-1.999999998"),(30, "1.999999999"),(31, "-1.999999999"),(32, "9.000000000"),(33, "-9.000000000"),(34, "9.000000001"),(35, "-9.000000001"),(36, "9.000000009"),(37, "-9.000000009"),(38, "9.099999999"),(39, "-9.099999999"),
      (40, "9.900000000"),(41, "-9.900000000"),(42, "9.900000001"),(43, "-9.900000001"),(44, "9.999999998"),(45, "-9.999999998"),(46, "9.999999999"),(47, "-9.999999999"),(48, "99999999999999999.000000000"),(49, "-99999999999999999.000000000"),(50, "99999999999999999.000000001"),(51, "-99999999999999999.000000001"),(52, "99999999999999999.000000009"),(53, "-99999999999999999.000000009"),(54, "99999999999999999.099999999"),(55, "-99999999999999999.099999999"),(56, "99999999999999999.900000000"),(57, "-99999999999999999.900000000"),(58, "99999999999999999.900000001"),(59, "-99999999999999999.900000001"),
      (60, "99999999999999999.999999998"),(61, "-99999999999999999.999999998"),(62, "99999999999999999.999999999"),(63, "-99999999999999999.999999999"),(64, "900000000000000000.000000000"),(65, "-900000000000000000.000000000"),(66, "900000000000000000.000000001"),(67, "-900000000000000000.000000001"),(68, "900000000000000000.000000009"),(69, "-900000000000000000.000000009"),(70, "900000000000000000.099999999"),(71, "-900000000000000000.099999999"),(72, "900000000000000000.900000000"),(73, "-900000000000000000.900000000"),(74, "900000000000000000.900000001"),(75, "-900000000000000000.900000001"),(76, "900000000000000000.999999998"),(77, "-900000000000000000.999999998"),(78, "900000000000000000.999999999"),(79, "-900000000000000000.999999999"),
      (80, "900000000000000001.000000000"),(81, "-900000000000000001.000000000"),(82, "900000000000000001.000000001"),(83, "-900000000000000001.000000001"),(84, "900000000000000001.000000009"),(85, "-900000000000000001.000000009"),(86, "900000000000000001.099999999"),(87, "-900000000000000001.099999999"),(88, "900000000000000001.900000000"),(89, "-900000000000000001.900000000"),(90, "900000000000000001.900000001"),(91, "-900000000000000001.900000001"),(92, "900000000000000001.999999998"),(93, "-900000000000000001.999999998"),(94, "900000000000000001.999999999"),(95, "-900000000000000001.999999999"),(96, "999999999999999998.000000000"),(97, "-999999999999999998.000000000"),(98, "999999999999999998.000000001"),(99, "-999999999999999998.000000001"),
      (100, "999999999999999998.000000009"),(101, "-999999999999999998.000000009"),(102, "999999999999999998.099999999"),(103, "-999999999999999998.099999999"),(104, "999999999999999998.900000000"),(105, "-999999999999999998.900000000"),(106, "999999999999999998.900000001"),(107, "-999999999999999998.900000001"),(108, "999999999999999998.999999998"),(109, "-999999999999999998.999999998"),(110, "999999999999999998.999999999"),(111, "-999999999999999998.999999999"),(112, "999999999999999999.000000000"),(113, "-999999999999999999.000000000"),(114, "999999999999999999.000000001"),(115, "-999999999999999999.000000001"),(116, "999999999999999999.000000009"),(117, "-999999999999999999.000000009"),(118, "999999999999999999.099999999"),(119, "-999999999999999999.099999999"),
      (120, "999999999999999999.900000000"),(121, "-999999999999999999.900000000"),(122, "999999999999999999.900000001"),(123, "-999999999999999999.900000001"),(124, "999999999999999999.999999998"),(125, "-999999999999999999.999999998"),(126, "999999999999999999.999999999"),(127, "-999999999999999999.999999999")
      ,(128, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimalv2_27_9_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimalv2_27_9_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimalv2_27_9_0_not_nullable;"
    sql "create table test_cast_to_float_from_decimalv2_27_9_0_not_nullable(f1 int, f2 decimalv2(27, 9)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimalv2_27_9_0_not_nullable values (0, "0.000000000"),(1, "0.000000000"),(2, "0.000000001"),(3, "-0.000000001"),(4, "0.000000009"),(5, "-0.000000009"),(6, "0.099999999"),(7, "-0.099999999"),(8, "0.900000000"),(9, "-0.900000000"),(10, "0.900000001"),(11, "-0.900000001"),(12, "0.999999998"),(13, "-0.999999998"),(14, "0.999999999"),(15, "-0.999999999"),(16, "1.000000000"),(17, "-1.000000000"),(18, "1.000000001"),(19, "-1.000000001"),
      (20, "1.000000009"),(21, "-1.000000009"),(22, "1.099999999"),(23, "-1.099999999"),(24, "1.900000000"),(25, "-1.900000000"),(26, "1.900000001"),(27, "-1.900000001"),(28, "1.999999998"),(29, "-1.999999998"),(30, "1.999999999"),(31, "-1.999999999"),(32, "9.000000000"),(33, "-9.000000000"),(34, "9.000000001"),(35, "-9.000000001"),(36, "9.000000009"),(37, "-9.000000009"),(38, "9.099999999"),(39, "-9.099999999"),
      (40, "9.900000000"),(41, "-9.900000000"),(42, "9.900000001"),(43, "-9.900000001"),(44, "9.999999998"),(45, "-9.999999998"),(46, "9.999999999"),(47, "-9.999999999"),(48, "99999999999999999.000000000"),(49, "-99999999999999999.000000000"),(50, "99999999999999999.000000001"),(51, "-99999999999999999.000000001"),(52, "99999999999999999.000000009"),(53, "-99999999999999999.000000009"),(54, "99999999999999999.099999999"),(55, "-99999999999999999.099999999"),(56, "99999999999999999.900000000"),(57, "-99999999999999999.900000000"),(58, "99999999999999999.900000001"),(59, "-99999999999999999.900000001"),
      (60, "99999999999999999.999999998"),(61, "-99999999999999999.999999998"),(62, "99999999999999999.999999999"),(63, "-99999999999999999.999999999"),(64, "900000000000000000.000000000"),(65, "-900000000000000000.000000000"),(66, "900000000000000000.000000001"),(67, "-900000000000000000.000000001"),(68, "900000000000000000.000000009"),(69, "-900000000000000000.000000009"),(70, "900000000000000000.099999999"),(71, "-900000000000000000.099999999"),(72, "900000000000000000.900000000"),(73, "-900000000000000000.900000000"),(74, "900000000000000000.900000001"),(75, "-900000000000000000.900000001"),(76, "900000000000000000.999999998"),(77, "-900000000000000000.999999998"),(78, "900000000000000000.999999999"),(79, "-900000000000000000.999999999"),
      (80, "900000000000000001.000000000"),(81, "-900000000000000001.000000000"),(82, "900000000000000001.000000001"),(83, "-900000000000000001.000000001"),(84, "900000000000000001.000000009"),(85, "-900000000000000001.000000009"),(86, "900000000000000001.099999999"),(87, "-900000000000000001.099999999"),(88, "900000000000000001.900000000"),(89, "-900000000000000001.900000000"),(90, "900000000000000001.900000001"),(91, "-900000000000000001.900000001"),(92, "900000000000000001.999999998"),(93, "-900000000000000001.999999998"),(94, "900000000000000001.999999999"),(95, "-900000000000000001.999999999"),(96, "999999999999999998.000000000"),(97, "-999999999999999998.000000000"),(98, "999999999999999998.000000001"),(99, "-999999999999999998.000000001"),
      (100, "999999999999999998.000000009"),(101, "-999999999999999998.000000009"),(102, "999999999999999998.099999999"),(103, "-999999999999999998.099999999"),(104, "999999999999999998.900000000"),(105, "-999999999999999998.900000000"),(106, "999999999999999998.900000001"),(107, "-999999999999999998.900000001"),(108, "999999999999999998.999999998"),(109, "-999999999999999998.999999998"),(110, "999999999999999998.999999999"),(111, "-999999999999999998.999999999"),(112, "999999999999999999.000000000"),(113, "-999999999999999999.000000000"),(114, "999999999999999999.000000001"),(115, "-999999999999999999.000000001"),(116, "999999999999999999.000000009"),(117, "-999999999999999999.000000009"),(118, "999999999999999999.099999999"),(119, "-999999999999999999.099999999"),
      (120, "999999999999999999.900000000"),(121, "-999999999999999999.900000000"),(122, "999999999999999999.900000001"),(123, "-999999999999999999.900000001"),(124, "999999999999999999.999999998"),(125, "-999999999999999999.999999998"),(126, "999999999999999999.999999999"),(127, "-999999999999999999.999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimalv2_27_9_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimalv2_27_9_0_not_nullable order by 1;'

}